<?php
ob_start();
session_start();
if(!isset($_SESSION['user'])){
	echo  "请你先登陆<a href=\"/index.php\">login</a>";
	exit();
}
?>

<div data-role="page">

<div data-role="header" data-position="inline" data-theme="c" class="ui-header ui-bar-c" role="banner">
			<a href="/home.php" data-icon="home" iconpos="notext" class="ui-btn-left ui-btn ui-btn-up-c ui-btn-icon-left ui-btn-corner-all ui-shadow" data-theme="c"><span class="ui-btn-inner ui-btn-corner-all" aria-hidden="true"><span class="ui-btn-text">返回主页</span><span class="ui-icon ui-icon-home ui-icon-shadow"></span></span></a>
			<h1 class="ui-title" tabindex="0" role="heading" aria-level="1">查看记录</h1>
			<a href="/user/inout.html" data-icon="arrow-r" data-iconpos="right" data-theme="b" class="ui-btn-right ui-btn ui-btn-up-b ui-btn-icon-right ui-btn-corner-all ui-shadow"><span class="ui-btn-inner ui-btn-corner-all" aria-hidden="true"><span class="ui-btn-text">添加记录</span><span class="ui-icon ui-icon-arrow-r ui-icon-shadow"></span></span></a>
	
	</div><!-- /header -->
<div data-role="content">
	<style>
		table { width:100%; background:#f3f7f5; }
		table caption { text-align:left;  }
		table thead th { text-align:left; border-bottom-width:1px; border-top-width:1px; }
		table th, td { text-align:left; padding:6px;} 
		.pages a
		{
			padding:5px 10px;
		}
		.pages em
		{
			padding-right:10px;
		}
		.tableFloatingHeader
		{
			color: white; 
			background-color: black;
		}
	</style>

	<script type="text/javascript">
		$("tr:odd").css("background-color", "#bbbbff");
        function UpdateTableHeaders() {

            $("div.divTableWithFloatingHeader").each(function() {

                var originalHeaderRow = $(".tableFloatingHeaderOriginal", this);

                var floatingHeaderRow = $(".tableFloatingHeader", this);

                var offset = $(this).offset();

                var scrollTop = $(window).scrollTop();

                if ((scrollTop > offset.top) && (scrollTop < offset.top + $(this).height())) {

                    floatingHeaderRow.css("visibility", "visible");

                    floatingHeaderRow.css("top", Math.min(scrollTop - offset.top, $(this).height() - floatingHeaderRow.height()) + "px");

                    // Copy cell widths from original header

                    $("th", floatingHeaderRow).each(function(index) {

                        var cellWidth = $("th", originalHeaderRow).eq(index).css('width');

                        $(this).css('width', cellWidth);
                    });

                    // Copy row width from whole table

                    floatingHeaderRow.css("width", $(this).css("width"));
                }
                else {
                    floatingHeaderRow.css("visibility", "hidden");
                    floatingHeaderRow.css("top", "0px");
                }
            });
        }

        $(document).ready(function() {

            $("table.tableWithFloatingHeader").each(function() {
                $(this).wrap("<div class=\"divTableWithFloatingHeader\" style=\"position:relative\"></div>");
                var originalHeaderRow = $("tr:first", this)
                originalHeaderRow.before(originalHeaderRow.clone());
                var clonedHeaderRow = $("tr:first", this)
                clonedHeaderRow.addClass("tableFloatingHeader");
                clonedHeaderRow.css("position", "absolute");
                clonedHeaderRow.css("top", "0px");
                clonedHeaderRow.css("left", $(this).css("margin-left"));
                clonedHeaderRow.css("visibility", "hidden");
                originalHeaderRow.addClass("tableFloatingHeaderOriginal");
            });
            UpdateTableHeaders();
            $(window).scroll(UpdateTableHeaders);
            $(window).resize(UpdateTableHeaders);
        });

    </script>
<a href="statistics.php" title="各类小计" >各类小计</a>
<table summary="账单列表" class="tableWithFloatingHeader">
  <thead style=" background-color: gray; color: whitesmoke;">
	<tr>
		<th scope="col">收支项</th>
		<th scope="col">金额</th>
		<th scope="col">类别</th>
		<th scope="col">说明</th>
		<th scope="col">日期</th>
		<th scope="col">操作</th>
	</tr>
  </thead>
  
<?php
require('../config.php');
require('page.class.php');
mysql_select_db(SAE_MYSQL_DB,$conn) or die("数据库".SAE_MYSQL_DB."连接失败!");
$spenduser=$_SESSION['uid'];
$met=$_GET['ac'];
$spendor=($met=='srlist')?2:1;
$curpage=isset($_GET['page'])?intval($_GET['page']):1;
$num=15;
$pagenum=ceil($total/$num);                                    
$offset=($curpage-1)*$num; 
$mpurl=htmlspecialchars($_SERVER['PHP_SELF']."?ac=$met");
//当月记录数
$sumstr="SELECT count(*) FROM sp WHERE spuserid='$spenduser' AND spendor='$spendor' and month(sptime)=month(now())";
//花销总额
$sum="SELECT sum(spmoney) FROM sp WHERE spuserid='$spenduser' AND spendor='$spendor'";
$sumthismonth="SELECT sum(spmoney) FROM sp WHERE spuserid='$spenduser' AND spendor='$spendor' and month(sptime)=month(now())";
#$sumlastmonth="SELECT sum(spmoney) FROM sp WHERE spuserid='$spenduser' AND spendor='$spendor' and month(sptime)=month(now())-1";
#$sumlastmonth1="SELECT sum(spmoney) FROM sp WHERE spuserid='$spenduser' AND spendor='$spendor' and month(sptime)=month(now())-2";
$result=mysql_query($sumstr,$conn);
$result1=mysql_query($sum,$conn);
$result2=mysql_query($sumthismonth,$conn);
#$result3=mysql_query($sumlastmonth,$conn);
#$result4=mysql_query($sumlastmonth1,$conn);
$myrow=mysql_fetch_array($result); 
$myrow1=mysql_fetch_array($result1); 
$myrow2=mysql_fetch_array($result2); 
#$myrow3=mysql_fetch_array($result3);
#$myrow4=mysql_fetch_array($result4);
$total=$myrow[0];
$info="SELECT * FROM sp WHERE spuserid='$spenduser' AND spendor='$spendor' and month(sptime)=month(now()) order by sptimef desc limit $offset,$num";
$result3=mysql_query($info,$conn);
$j=0;
	echo ' <tfoot><tr><td colspan="6">';
	echo multi($total, $num, $curpage, $mpurl);
	echo '</td></tr></tfoot>'; 
	echo '<tbody>';
while($list=mysql_fetch_array($result3)){
	$j++;
	echo '<tr><th scrop=\'row\'>'.$list['spname'].'</th><td class=\'money\'>'.$list['spmoney'].'</td><td >'.$list['spopt'].'</td><td>'.$list['spsay'].'</td><td >'.$list['sptime'].'</td><td>'."<a href=del.php?s=$spendor&u=$spenduser&iod=$list[spid]><img src='/images/del.gif' border=0 alt='del'></a>".'</td></tr>';
	}
	echo '</tbody></table>';
echo '<div class=\'footer\'>';
echo '<h3>当月花销&nbsp;'.round($myrow2[0]).'元</h3>';
#echo '<h3>上月花销&nbsp;'.round($myrow3[0]).'元</h3>';
#echo '<h3>上上月花销&nbsp;'.round($myrow4[0]).'元</h3>';
echo '<h3>总计花销&nbsp;'.round($myrow1[0]).'元</h3>';
ob_end_flush();
echo '</div>';
?>
 
</div>

<div data-role="footer">
<h1>我爱宝宝@香柱元</h1>
</div>
</div>
